
<template>
  <a-table :columns="columns" :data-source="MyLostDataList">
    <a slot="name" slot-scope="text">{{ text }}</a>
    <span slot="customTitle"><a-icon type="smile-o" /> Name</span>
    <span slot="tags" slot-scope="tags">
      <a-tag
          v-for="tag in tags"
          :key="tag"
          :color="tag === 'loser' ? 'volcano' : tag.length > 5 ? 'geekblue' : 'green'"
      >
        {{ tag.toUpperCase() }}
      </a-tag>
    </span>

    <span slot="action" slot-scope="text, record">


      <a-popconfirm
          title="您确定要删除当前帖子?"
          ok-text="Yes"
          cancel-text="No"
          @confirm="deleteLost(record.lostId)"
          @cancel="()=>{}"
      >
    <a>删除帖子</a>
  </a-popconfirm>

      <a-divider type="vertical" />

      <a-popconfirm
          title="您确定要确认当前物品已经找到?"
          ok-text="Yes"
          cancel-text="No"
          @confirm="lostAndFoundOk(record.lostId)"
          @cancel="()=>{}"
      >
    <a>确认物品已经找到</a>
  </a-popconfirm>
    </span>

  </a-table>
</template>

<script>
import { message } from 'ant-design-vue';
const columns = [
  {
    title: '标题',
    dataIndex: 'title',
    key: 'title',
  },
  {
    title: '类别',
    dataIndex: 'lostType',
    key: 'lostType',
  },
  {
    title: '内容',
    dataIndex: 'text',
    key: 'text',
  },
  {
    title: '状态',
    dataIndex: 'state',
    key: 'state',
  },
  {
    title: '标签',
    key: 'tagsString',
    dataIndex: 'tagsString',
  },
  {
    title: '操作',
    key: 'action',
    scopedSlots: { customRender: 'action' },
  },
];



export default ({
  data() {
    return {
      MyLostDataList:[],
      columns
    }
  },
 beforeCreate() {
    //创建之前拉取数据
   this.$http({
     method: 'get',
     url: 'http://localhost:18082/loatandfound/getusersendaLl',
     headers:{
       user:localStorage.getItem("user"),
     }
   }).then((e)=>{
     let clList=[];
     e.data.data.forEach(item=>{

       let tagsString="";
       item.labels.forEach(item=>{
         tagsString=tagsString+"-"+item.name;
       })

       clList.push({
         ...item,
         tagsString:tagsString
       })

     })
     this.MyLostDataList=clList;

     console.log("查看当前事项",e);

   })



 },
  mounted() {

  },
  methods: {
    deleteLost(e){

      console.log("删除帖子")
      this.$http({
        method: 'delete',
        url: 'http://localhost:18082/loatandfound/delete',
        data: {
          lostId:e
        },
        headers:{
          user:localStorage.getItem("user"),
        }
      }).then((e)=>{

        if(e.data.status){
          message.info("删除成功！",3);

          this.$http({
            method: 'get',
            url: 'http://localhost:18082/loatandfound/getusersendaLl',
            headers:{
              user:localStorage.getItem("user"),
            }
          }).then((e)=>{
            let clList=[];
            e.data.data.forEach(item=>{

              let tagsString="";
              item.labels.forEach(item=>{
                tagsString=tagsString+"-"+item.name;
              })

              clList.push({
                ...item,
                tagsString:tagsString
              })

            })
            this.MyLostDataList=clList;

            console.log("查看当前事项",e);

          })

        }else{
          message.error("删除失败！",3);
        }


      })

    },
    lostAndFoundOk(e){



      console.log("物品确认",e)
      this.$http({
        method: 'post',
        url: 'http://localhost:18082/loatandfound/lostandfoundok',
        data: {
          lostId:e
        },
        headers:{
          user:localStorage.getItem("user"),
        }
      }).then((e)=>{


        if(e.data.status==true){
          message.info("物品确认成功！",3);
          this.$http({
            method: 'get',
            url: 'http://localhost:18082/loatandfound/getusersendaLl',
            headers:{
              user:localStorage.getItem("user"),
            }
          }).then((e)=>{
            let clList=[];
            e.data.data.forEach(item=>{

              let tagsString="";
              item.labels.forEach(item=>{
                tagsString=tagsString+"-"+item.name;
              })

              clList.push({
                ...item,
                tagsString:tagsString
              })

            })
            this.MyLostDataList=clList;

            console.log("查看当前事项",e);

          })
        }else{
          message.error("物品确认失败！",3);
        }

      })

    }
  },
})

</script>

